#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os, sys

import akshare as ak
from unit import isneedupdate
from database import con,droptable

def filempath(path,name):
    path =  os.path.join(os.path.expanduser("~"), path, name + '.csv')
    return  path


def update_etf_basic():
    print("更新ETF列表")
    path = os.path.join(os.path.expanduser("~"), "stockdate/cvs", "etf_basic" + '.csv')
    if isneedupdate(path)== True:
        print("ETF列表需要更新")
        df = ak.fund_etf_category_sina(symbol="ETF基金")
        df = df.drop(["code"], axis=1)
        df = df.rename(columns={'symbol': 'code'})
        df.to_csv(path)
        droptable("etfbasic")
        df = df[["code","name"]]
        df["changeTime"] = None
        df.to_sql('etfbasic', con=con, index=False, index_label = "code")
    else:
        print("ETF列表不需要更新")
